package com.kefu.exam.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kefu.common.annotation.Permission;
import com.kefu.common.controller.AbstractBaseController;
import com.kefu.common.result.Result;
import com.kefu.common.result.ResultGenerator;
import com.kefu.common.vo.DetailVo;
import com.kefu.exam.mapper.ExamPaperAnswerMapper;
import com.kefu.exam.model.ExamPaperAnswer;
import com.kefu.exam.service.ExamPaperAnswerService;
import com.kefu.exam.vo.ExamPaperAnswerBatchSubmitVo;
import com.kefu.exam.vo.ExamPaperAnswerInsertVo;
import com.kefu.exam.vo.ExamPaperAnswerSearchVo;
import com.kefu.exam.vo.ExamPaperAnswerVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author xy
 * @date 2022/02/28
 */
@Api(tags = "答题卡答案表")
@RestController
@RequestMapping("exam/cardAnswer")
public class ExamPaperAnswerController extends AbstractBaseController {
    @Resource
    private ExamPaperAnswerService examPaperAnswerService;

    @PostMapping("/add")
    @ApiOperation(value = "新增问卷答案", notes = "新增问卷答案")
    public Result<String> add(@Validated @RequestBody ExamPaperAnswerInsertVo examCardAnswerVo) {
    	logger.info("新增答题卡答案表:{}", examCardAnswerVo);
    	
        return ResultGenerator.genSuccessResult(examPaperAnswerService.addPaperAnswer(examCardAnswerVo));
    }

    @PostMapping("/batchSubmit")
    @ApiOperation(value = "提交问卷", notes = "提交问卷")
    public Result<String> batchAdd(@Validated @RequestBody ExamPaperAnswerBatchSubmitVo batchSubmitVo) {
        logger.info("新增答题卡答案表:{}", batchSubmitVo);

        return ResultGenerator.genSuccessResult(examPaperAnswerService.batchSubmit(batchSubmitVo));
    }

    @PostMapping("/getActivityPaperInfo")
    @ApiOperation(value = "获取拨打清单问卷填写信息", notes = "获取拨打清单问卷填写信息")
    public Result<List> get(@Validated @RequestBody DetailVo detailVo) {

        return ResultGenerator.genSuccessResult(examPaperAnswerService.getActivityPaperInfo(detailVo.getId()));
    }

    @PostMapping("/list")
    @ApiOperation(value = "查询试卷答案", notes = "查询试卷答案")
    public Result<Page<ExamPaperAnswer>> list(@Validated @RequestBody ExamPaperAnswerSearchVo search) {

        Page<ExamPaperAnswer> page = examPaperAnswerService.searchLambdaPage(search);
        return ResultGenerator.genSuccessResult(page);
    }
}
